package com.likou;

/**
 * Author: 陈桂明
 * Date: 2025/4/16 0:43
 * Description: q238
 */
public class q238 {
    public int[] productExceptSelf(int[] nums) {
        if (nums.length == 1) {
            return nums;
        }

        int[] ans = new int[nums.length];
        ans[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            ans[i] = ans[i - 1] * nums[i - 1];
        }

        int temp = 1;
        for (int j = nums.length - 2; j >= 0; j--) {
            temp *= nums[j + 1];
            ans[j] = ans[j] * temp;
        }
        return ans;
    }
}
